﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.SupplierVMs
{
    public partial class SupplierListVM : BasePagedListVM<Supplier_View, SupplierSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Supplier_View>> InitGridHeader()
        {
            return new List<GridColumn<Supplier_View>>{
                
                this.MakeGridHeader(x => x.Supplier_SupplierCode).SetTitle(@Localizer["Page.供应商编码"].Value),
                this.MakeGridHeader(x => x.Supplier_SupplierName).SetTitle(@Localizer["Page.供应商名称"].Value),
                this.MakeGridHeader(x => x.Supplier_ContactPerson).SetTitle(@Localizer["Page.联系人"].Value),
                this.MakeGridHeader(x => x.Supplier_PhoneNumber).SetTitle(@Localizer["Page.手机号码"].Value),
                this.MakeGridHeader(x => x.Supplier_Email).SetTitle(@Localizer["_Admin.Email"].Value),
                this.MakeGridHeader(x => x.Supplier_Faxing).SetTitle(@Localizer["Page.传真"].Value),
                this.MakeGridHeader(x => x.Supplier_BeginPay).SetTitle(@Localizer["Page.期初应付"].Value),
                this.MakeGridHeader(x => x.Supplier_EndPay).SetTitle(@Localizer["Page.期末应付"].Value),
                this.MakeGridHeader(x => x.Supplier_TaxtRate).SetTitle(@Localizer["Page.税率"].Value),
                this.MakeGridHeader(x => x.Supplier_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.Supplier_Address).SetTitle(@Localizer["_Admin.Address"].Value),
                this.MakeGridHeader(x => x.Supplier_Bank).SetTitle(@Localizer["Page.开户行"].Value),
                this.MakeGridHeader(x => x.Supplier_TaxpayerNumber).SetTitle(@Localizer["Page.纳税人识别号"].Value),
                this.MakeGridHeader(x => x.Supplier_BankAccount).SetTitle(@Localizer["Page.银行账号"].Value),
                this.MakeGridHeader(x => x.Supplier_LandlinePhone).SetTitle(@Localizer["Page.固定电话"].Value),
                this.MakeGridHeader(x => x.Supplier_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Supplier_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Supplier_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Supplier_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.Supplier_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Supplier_View> GetSearchQuery()
        {
            var query = DC.Set<Supplier>()
                
                .CheckContain(Searcher.SupplierCode, x=>x.SupplierCode)
                .CheckContain(Searcher.SupplierName, x=>x.SupplierName)
                .CheckContain(Searcher.ContactPerson, x=>x.ContactPerson)
                .CheckEqual(Searcher.PhoneNumber, x=>x.PhoneNumber)
                .CheckContain(Searcher.Email, x=>x.Email)
                .CheckContain(Searcher.Faxing, x=>x.Faxing)
                .CheckEqual(Searcher.BeginPay, x=>x.BeginPay)
                .CheckEqual(Searcher.EndPay, x=>x.EndPay)
                .CheckEqual(Searcher.TaxtRate, x=>x.TaxtRate)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckContain(Searcher.Bank, x=>x.Bank)
                .CheckContain(Searcher.TaxpayerNumber, x=>x.TaxpayerNumber)
                .CheckContain(Searcher.BankAccount, x=>x.BankAccount)
                .CheckContain(Searcher.LandlinePhone, x=>x.LandlinePhone)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Supplier_View
                {
				    ID = x.ID,
                    
                    Supplier_SupplierCode = x.SupplierCode,
                    Supplier_SupplierName = x.SupplierName,
                    Supplier_ContactPerson = x.ContactPerson,
                    Supplier_PhoneNumber = x.PhoneNumber,
                    Supplier_Email = x.Email,
                    Supplier_Faxing = x.Faxing,
                    Supplier_BeginPay = x.BeginPay,
                    Supplier_EndPay = x.EndPay,
                    Supplier_TaxtRate = x.TaxtRate,
                    Supplier_Remark = x.Remark,
                    Supplier_Address = x.Address,
                    Supplier_Bank = x.Bank,
                    Supplier_TaxpayerNumber = x.TaxpayerNumber,
                    Supplier_BankAccount = x.BankAccount,
                    Supplier_LandlinePhone = x.LandlinePhone,
                    Supplier_CreateTime = x.CreateTime,
                    Supplier_UpdateTime = x.UpdateTime,
                    Supplier_CreateBy = x.CreateBy,
                    Supplier_UpdateBy = x.UpdateBy,
                    Supplier_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Supplier_View: Supplier
    {
        
        public string Supplier_SupplierCode { get; set; }
        public string Supplier_SupplierName { get; set; }
        public string Supplier_ContactPerson { get; set; }
        public string Supplier_PhoneNumber { get; set; }
        public string Supplier_Email { get; set; }
        public string Supplier_Faxing { get; set; }
        public decimal? Supplier_BeginPay { get; set; }
        public decimal? Supplier_EndPay { get; set; }
        public decimal? Supplier_TaxtRate { get; set; }
        public string Supplier_Remark { get; set; }
        public string Supplier_Address { get; set; }
        public string Supplier_Bank { get; set; }
        public string Supplier_TaxpayerNumber { get; set; }
        public string Supplier_BankAccount { get; set; }
        public string Supplier_LandlinePhone { get; set; }
        public DateTime? Supplier_CreateTime { get; set; }
        public DateTime? Supplier_UpdateTime { get; set; }
        public string Supplier_CreateBy { get; set; }
        public string Supplier_UpdateBy { get; set; }
        public bool Supplier_IsValid { get; set; }

    }

}